<?php
/*Breadcrumb function*/
function get_fil_ariane($array_fil) {
	$fil = '<a href="index.php">Home</a>';
	if (empty($array_fil))
		return ("<b>Home</b>");
	foreach($array_fil as $url => $lien) {
		$fil .= ' > ';
		if($url == 'final') {
			$fil .= $lien;
			break;
		}
		$fil .= '<a href="' . $url . '">' . $lien . '</a>';
	}
	return $fil;
}

function is_following($follower, $followed){
	$query = "SELECT date FROM followers WHERE follower='$follower' AND followed='$followed'";
	$result = bdd_query($query);
	if (mysql_num_rows($result) == 0)
		return (0);
	else
		return (1);
}

/*Create Article*/
function create_article($params) {
	$query = "INSERT INTO articles (id_user, title, text, link_img, link_vid, date) VALUES ('$params[5]', '$params[0]', '$params[4]', '$params[1]', '$params[2]', '$params[6]');";
	$result = bdd_query($query);
	return ($result);
}

/*Create Comment*/
function create_comment($params) {
	$query = "INSERT INTO comments (id_article, id_user, text, date) VALUES ('$params[0]', '$params[2]', '$params[1]', '$params[3]');";
	$result = bdd_query($query);
	return ($result);
}

/*find the id_genre from genre name*/
function find_genre($genre){
	$query = "SELECT id_genre FROM genre WHERE genre='$genre'";
	$result = bdd_query($query);
	$res = mysql_fetch_row($result);
	return ($res[0]);
}

/*Update film*/
function update_film($id, $params){
	$query = "UPDATE films SET ";
	foreach ($params as $key => $val)
	{
		$query .= $val[0] . "='" . $val[1] . "'";
		if ($key != (count($params) - 1))
			$query .= ', ';
		else
			$query .= ' ';
	}
	$query .= "WHERE id='$id'";
	$result = bdd_query($query);
	return ($result);
}
/*Check existing user in database*/ 
function check_account($login, $pass) 
{
	$login = htmlentities($login);
	$pass = md5(htmlentities($pass));
	if ($login == "'")
		return ("nice try");
	$query = "SELECT login,password FROM users WHERE login='$login'";
	$result = bdd_query($query);
	if (empty($result))
		return ("user not found");
	else
	{
		$res = mysql_fetch_array($result);
		if ($res[0] == $login && $res[1] == $pass)
			return (true);
		else 
			return ("wrong password or login");
	}
}

?>